package com.yztc.wl.zhibo.totalfragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yztc.wl.zhibo.R;
import com.yztc.wl.zhibo.adapter.OnePagerAdapter;
import com.yztc.wl.zhibo.oneclassfragment.HomeWorkFragment;
import com.yztc.wl.zhibo.oneclassfragment.QueryFragment;
import com.yztc.wl.zhibo.oneclassfragment.SchoolFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wlpc on 2016/11/4.
 */
public class OneFragment extends Fragment {
    private TabLayout tabs;
    private ViewPager viewPager;
    private List<String> tabNames;
    private List<Fragment> fragments;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one,container,false);
        viewPager= (ViewPager) view.findViewById(R.id.one_viewpager);
        tabs= (TabLayout) view.findViewById(R.id.one_tablayout);
        tabNames = new ArrayList<>();
        fragments = new ArrayList<>();

        tabNames.add("学校公告");
        tabNames.add("成绩查询");
        tabNames.add("作业布置");

        HomeWorkFragment homeWorkFragment =new HomeWorkFragment();
        QueryFragment queryFragment = new QueryFragment();
        SchoolFragment schoolFragment = new SchoolFragment();
        fragments.add(schoolFragment);
        fragments.add(queryFragment);
        fragments.add(homeWorkFragment);

        OnePagerAdapter onePagerAdapter = new OnePagerAdapter(getFragmentManager(),fragments,tabNames);
        viewPager.setAdapter(onePagerAdapter);
        tabs.setupWithViewPager(viewPager);
        return view;
    }
}
